package com.ruoyi.web.controller.business.finance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.OrderSettlement;
import com.ruoyi.business.service.IOrderSettlementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 结算单Controller
 * 
 * @author ruoyi
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/business/finance/settlement")
public class OrderSettlementController extends BaseController
{
    @Autowired
    private IOrderSettlementService orderSettlementService;

    /**
     * 查询结算单列表
     */
    @PreAuthorize("@ss.hasPermi('business:finance:settlement:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderSettlement orderSettlement)
    {
        startPage();
        List<OrderSettlement> list = orderSettlementService.selectOrderSettlementList(orderSettlement);
        return getDataTable(list);
    }

    /**
     * 导出结算单列表
     */
    @PreAuthorize("@ss.hasPermi('business:finance:settlement:export')")
    @Log(title = "结算单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderSettlement orderSettlement)
    {
        List<OrderSettlement> list = orderSettlementService.selectOrderSettlementList(orderSettlement);
        ExcelUtil<OrderSettlement> util = new ExcelUtil<OrderSettlement>(OrderSettlement.class);
        util.exportExcel(response, list, "结算单数据");
    }

    /**
     * 获取结算单详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:finance:settlement:query')")
    @GetMapping(value = "/{settlementId}")
    public AjaxResult getInfo(@PathVariable("settlementId") Long settlementId)
    {
        return success(orderSettlementService.selectOrderSettlementBySettlementId(settlementId));
    }

    /**
     * 新增结算单
     */
    @PreAuthorize("@ss.hasPermi('business:finance:settlement:add')")
    @Log(title = "结算单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderSettlement orderSettlement)
    {
        return toAjax(orderSettlementService.insertOrderSettlement(orderSettlement));
    }

    /**
     * 修改结算单
     */
    @PreAuthorize("@ss.hasPermi('business:finance:settlement:edit')")
    @Log(title = "结算单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderSettlement orderSettlement)
    {
        return toAjax(orderSettlementService.updateOrderSettlement(orderSettlement));
    }

    /**
     * 删除结算单
     */
    @PreAuthorize("@ss.hasPermi('business:finance:settlement:remove')")
    @Log(title = "结算单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{settlementIds}")
    public AjaxResult remove(@PathVariable Long[] settlementIds)
    {
        return toAjax(orderSettlementService.deleteOrderSettlementBySettlementIds(settlementIds));
    }
}
